<?php
/***
 * ,微信自动注册
 * by Argon 16/12/28 11:11
 */
namespace App\Controller\Index;

use Common\Model\MemberMessageModel;
use Common\Model\MemberModel;
use Common\Model\MemberOtherPlatformModel;
use Common\Model\MemberWeixinModel;
use Common\Model\MicroShopModel;
use Common\Model\TarentoCashFlowModel;
use Common\Model\TarentoModel;
use Think\Controller;

class WechatRegController extends Controller
{

    public function loginFromOtherPlatform(){
        $otherLoginPlatform = I('param.otherLoginPlatform');
        $mebmerOtherPlatformJson = I('param.mebmerOtherPlatformJson');
        $shop_id = I('param.shop_id');
        $mebmerOtherPlatformData = json_decode($mebmerOtherPlatformJson, true);

        try {
            $res = (new WechatServerController())->loginFromOtherPlatform($otherLoginPlatform, $mebmerOtherPlatformData,$shop_id);
        } catch (\Exception $e){
            $this->ajaxReturn(['code'=>300,'msg'=>'参数错误']) ;
        }
        //file_put_contents('/www/weiphp/aaaaaaaa3.txt',print_r($res,true),FILE_APPEND);
        $this->ajaxReturn(['code'=>200,'userInfo'=>$res]) ;
    }


    /**
     * 获取信息
     */
    public function getInfos(){
        $Openid = I('param.weixinUserOpenid');

        $fields = ["member_id"];
        $model = new MemberWeixinModel();
        $info = $model->where("unique_code='$Openid'")->field($fields)->find();
        if (!is_null($info)) {
            $info['memberId'] = $info['member_id'];
        }
        $this->ajaxReturn(['code'=>200,'info'=>$info]);
    }

    /**
     *获取用户微信的OpenId
     */
    public function getWeixinOpenSecretid(){
        $memberId = I('param.memberId');
        $model = new MemberWeixinModel();
        $data = $model->where("member_id=$memberId")->field("data")->find();
        $data = json_decode($data['data'],true);
        $res = [
            'code'=>200,
            'openSecretid' => $data['openid']
        ];
        $this->ajaxReturn($res);
    }
    /**
     *获取用户微信的昵称
     */
    public function getUserName(){
        $userid = I('param.shopId');
        $model = new MemberModel();
        $name = $model->where("id=$userid")->getField('name');
        $this->ajaxReturn(['code'=>200,'name'=>$name]);
    }

}